package com.mycompany.app.hr.common.longrunningtask;

/**
 * Progress Information
 * 
 * @author kevin.wang
 */
public class ProgressMeter  {
    int percentageComplete;

    private String status;

    private int total;

    private int currentCount;

    /**
     * Use this method to set the completion %age to object 10 of 30 etc.
     * 
     * @param count The current object count in progress
     * @param total The total number of objects to be processed
     */
    public void setPercentage(int count, int total) {

        if (total < 0) {
            percentageComplete = 0;
        } else if (total <= count) {
            percentageComplete = 100;
        } else {
            percentageComplete = ((int) (100 * (float) count / (float) total));

            if (count < total && percentageComplete == 100)
                percentageComplete = 99;
        }
    }

    public void setStatus(String status) {

        this.status = status;
    }

    public int getPercentageComplete() {

        return percentageComplete;
    }

    public String getStatus() {

        return status;
    }

    public void setPercentage(int percentageComplete) {

        this.percentageComplete = percentageComplete;
    }

    public int getCurrentCount() {

        return currentCount;
    }

    public void setCurrentCount(int currentCount) {

        this.currentCount = currentCount;
        updatePercentageComplete();
    }

    private void updatePercentageComplete() {

        setPercentage(getCurrentCount(), getTotal());
    }

    public int getTotal() {

        return total;
    }

    public void setTotalObjects(int total) {

        this.total = total;
        updatePercentageComplete();
    }
}